package PTA;

import java.util.Scanner;

interface Goods{
    public String getName();
    public double getPrice();
}
/////////////////////////////////////////
class Book implements Goods {
    String name;
    double price;
    public Book(String name,double price) {
        this.name = name;
        this.price = price;
    }
    public String getName() {
        return name;
    }
    public double getPrice() {
        return price;
    }
}
class Drink implements Goods {
    String name;
    double price;
    public Drink(String name,double price) {
        this.name = name;
        this.price = price;
    }
    public String getName() {
        return name;
    }
    public double getPrice() {
        return price;
    }
}
class ShopCar {
    Goods[] goods;
    static int foot = 0;
    public ShopCar(int num) {
        goods = new Goods[num];
    }
    public void add(Goods good) {
        if(foot < this.goods.length) {
            this.goods[foot] = good;
            foot++;
            System.out.println("添加成功！");
        }
        else {
            System.out.println("添加失败!");
            return;
        }
    }
    public void remove(int key) {
        if(key < this.goods.length && key >= 0) {
            for (int i = key; i < foot - 1; i++) {
                goods[i] = goods[i+1];
            }
            foot--;
            this.goods[goods.length-1] = null;
        }
    }
    public double check() {
        double sum = 0;
        for (int i = 0; i < foot; i++) {
            sum += goods[i].getPrice();
        }
        return sum;
    }
    public Goods[] getGoods() {
        return goods;
    }
}
/////////////////////////////////////////
public class t10 {
    public static void main(String[] args) {
        int n;
        Scanner scan=new Scanner(System.in);
        n=scan.nextInt();
        ShopCar sc=new ShopCar(n);
        sc.add(new Book("Java程序设计",78.5));
        sc.add(new Book("图像处理",44.5));
        sc.add(new Book("高等数学",34.8));
        sc.add(new Drink("绿茶",2.5));
        sc.add(new Drink("雪碧",3.5));
        sc.add(new Drink("可乐",5.5));
        sc.remove(3);
        for(int i=0;i<sc.getGoods().length;i++){
            if(sc.getGoods()[i]!=null)
                System.out.println("商品名称："+sc.getGoods()[i].getName()+"，价格："+sc.getGoods()[i].getPrice());
        }
        System.out.println("结账："+sc.check());
    }
}
